<script setup lang="ts">
  import { ref,inject } from 'vue'
  import { noticeList } from '@/api'
  const $Prefix = inject('$Prefix')
  const dataList = ref([])
  const paging = ref()
  const loadFun = (pageNo:number, pageSize:number) => {
    noticeList({pageNo,pageSize}).then(res => {
    if(res.code == 200){
      const data = JSON.parse(JSON.stringify(res.data.data))
      data.map((item:any) => {
        item.pic = item.pic ? JSON.parse(item.pic) : []
        return item
      })
      paging.value.complete(data)
    }else{
      paging.value.complete([])
    }
    }).catch(err => {
      paging.value.complete(false)
    })
  }
  const navigateTo = (url:string) => {
    uni.navigateTo({url})
  }
</script>

<template>
  <z-paging ref="paging" class="z-paging" v-model="dataList" @query="loadFun">
    <template #top>
      <xx-title :placeholder="false"/>
      <view class="header" :style="{backgroundImage:`url(${$Prefix}/public/images/smallImage/announcement.png)`}">
      </view>
    </template>
    <view class="announcement-item" @click="navigateTo(`/pages/announcementDetails/announcementDetails?id=${item.id}`)" v-for="(item,index) in dataList" :key="index">
      <view class="announcement-left" :class="{ 'no-right': item.pic.length > 0}">
        <view class="announcement-title">{{item.title}}</view>
        <view class="announcement-time">创建人：{{item.createdUserName}}</view>
        <view class="announcement-time">发布于：{{item.createdTime}}</view>
      </view>
      <view class="announcement-right" v-if="item.pic.length > 0">
        <image :src="item.pic[0].fullUrl"/>
      </view>
    </view>
  </z-paging>
</template>

<style scoped lang="scss">
  ::v-deep.z-paging-content{
    background: #F5F5F5;
  }
.header{
  width: 100%;
  height: 356rpx;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  .back-icon{
    position: absolute;
    width: 48rpx;
    height: 48rpx;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
.announcement-item{
  margin: 24rpx 32rpx;
  background-color: #FFFFFF;
  border-radius: 8rpx;
  padding: 20rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .announcement-left{
    height: 154rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: calc(100% - 242rpx);
    margin-right: 10rpx;
    .announcement-title{
      color: #21252E;
      font-size: 26rpx;
      line-height: 1.5;
      font-weight: 500;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .announcement-time{
      font-size: 24rpx;
      color: #818496;
    }
    &.no-right{
      width: 100%;
    }
  }
  .announcement-right{
    width: 232rpx;
    height: 154rpx;
    border-radius: 8rpx;
    overflow: hidden;
    image{
      width: 100%;
      height: 100%;
    }
  }
}
</style>
